#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 1e7 + 10;
const int MOD = 1e9 + 7;

ll d[MAXN];
int m[MAXN * 8];
void init() {
    for (int i = 1; i < MAXN; i++) {
        for (int j = i; j < MAXN; j+=i) {
            d[j] += i;
        }
    }

    for (int i = 1; i < MAXN; i++) {
        if (!m[d[i]]) m[d[i]] = i;
    }
}
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    clock_t startTime,endTime;
    startTime = clock();
    init();
    endTime = clock();

    cerr << (double)(endTime - startTime) / CLOCKS_PER_SEC * 1000 << "ms" << endl;

    int t;
    cin >> t;
    while(t--) {
        int c;
        cin >> c;
        if (!m[c]) cout << -1 << endl;
        else cout << m[c] << endl;
    }
    return 0;
}